<?php
namespace app\dsadmin\model;
use think\Model;
use think\Db;

class KlModel extends Model
{
    protected $name = 'kl';

    public function getKouliangByWhere($map, $Nowpage, $limits)
    {
        // return $this->where($map)->page($Nowpage, $limits)->order('id desc')->select();
        return Db::name('kl')->alias('k')->join('member m', 'k.userid=m.id', 'LEFT')->where($map)->page($Nowpage, $limits)->order('k.id desc')->field('k.*,m.account,m.nickname')->select();
    }
    
    

    public function getAllCount($map)
    {
        return $this->where($map)->count();
    }

    // public function delAllKouliang()
    // {
    //     try
    //     {
    //         $this->where(['id' => ['<>', 0]])->delete();
    //         $this->execute("truncate table ds_kl");
    //         return ['code' => 1, 'data' => '', 'msg' => '删除成功'];
    //     }
    //     catch(PDOException $e)
    //     {
    //         return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
    //     }
    // }
    
    public function delAllKouliang($map)
    {
        try
        {
            $this->where($map)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '清除成功'];
        }
        catch(PDOException $e)
        {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }

    public function delUser($id)
    {
        try
        {
            $this->where('id', $id)->delete();
            Db::name('auth_group_access')->where('uid', $id)->delete();
            return ['code' => 1, 'data' => '', 'msg' => '删除成功'];
        }
        catch(PDOException $e)
        {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }

    public function delKouliang($id)
    {
        try
        {
            $this->where(['id' => $id])->delete();
            return ['code' => 1, 'data' => '', 'msg' => '删除成功'];
        }
        catch(PDOException $e)
        {
            return ['code' => 0, 'data' => '', 'msg' => $e->getMessage()];
        }
    }
}
